/*
 * Created on 2004-5-21
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package com.dcivision.contact.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import com.dcivision.contact.bean.ContactList;
import com.dcivision.contact.bean.ContactPerson;
import com.dcivision.contact.bean.MtmContactListObjectLink;
import com.dcivision.contact.dao.MtmContactListObjectLinkDAObject;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.Utility;
import com.dcivision.framework.web.AbstractListAction;
import com.dcivision.framework.web.AbstractSearchForm;

/**
 * @author Administrator
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class ListContactPersonAction extends AbstractListAction {

  public static final String REVISION = "$Revision: 1.8 $";


	  /**
	   *  Constructor - Creates a new instance of ListContactCompanyAction and define the default listName.
	   */
	  public ListContactPersonAction() {
	    super();
	    this.setListName("contactPersonList");
	  }

	  /**
	   * getMajorDAOClassName
	   *
	   * @return  The class name of the major DAObject will be used in this action.
	   */
	  public String getMajorDAOClassName() {
	    return("com.dcivision.contact.dao.ContactPersonDAObject");
	  }

	  /**
	   * getFunctionCode
	   *
	   * @return  The corresponding system function code of action.
	   */
	  public String getFunctionCode() {
	    return(SystemFunctionConstant.CONTACT_PERSON);
	  }	 
      
    public void getListData(ActionMapping mapping,AbstractSearchForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
      super.getListData(mapping,form,request,response);
      List list=(List)request.getAttribute(this.getListName());
      for(int i=0;i<list.size();i++){
        ContactPerson contactPerson=(ContactPerson)list.get(i); 
        if(ContactList.SHARING_TYPE_PUB.equals(contactPerson.getPublicFlag())){
          contactPerson.setPublicFlag("public");
        }else{
          contactPerson.setPublicFlag("private"); 
        }
      }
      request.setAttribute(this.getListName(),list);
    }
	  	  
	  public void deleteListData(ActionMapping mapping, AbstractSearchForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
	    super.deleteListData(mapping, form,request,response);
	    MtmContactListObjectLinkDAObject mtmContactListObjectLinkDAO=new MtmContactListObjectLinkDAObject(this.getSessionContainer(request), this.getConnection(request));

      if(!Utility.isEmpty(form.getBasicSelectedID())){
        for(int i=0;i<form.getBasicSelectedID().length;i++){
          Integer selectID=TextUtility.parseIntegerObj(form.getBasicSelectedID()[i]);         
          mtmContactListObjectLinkDAO.deleteByObjectIDObjectType(selectID,MtmContactListObjectLink.OBJECT_TYPE_CONTACT_PERSON);
        }
      }
	  }	 	  
}
